<template>
    <div class="mainDiv" style="padding:20px;box-sizing: border-box;">
        <el-select v-model="cid" placeholder="请选择所属主分类！" style="margin: 10px 0">
            <el-option v-for="c in cates" :label="c.name" :value="c.id" :key="c.id">
            </el-option>
        </el-select>
        <el-input placeholder="请输入诊断类型名称！" v-model="name" style="margin: 10px 0">
            <template slot="prepend">诊断类型</template>
        </el-input>
        <div style="display: flex;">
            <el-button @click.native="close" style="width: 50%">取消</el-button>
            <el-button type="success" @click.native="callSubmit" :loading="loading" style="width: 50%">确定</el-button>
        </div>
    </div>
</template>
<script>
import C from '@/common/common.js'
export default {
  name: 'userselectzhiwei',
  data () {
    return {
      RequestUrl: {},
      cates: [],
      cid: '',
      name: '',
      id: '',
      loading: false
    }
  },
  async mounted () {
    this.RequestUrl = C.getDatas()
    if (this.RequestUrl.obj) {
      this.cid = this.RequestUrl.obj.pid || ''
      this.name = this.RequestUrl.obj.name || ''
      this.id = this.RequestUrl.obj.id || ''
    }
    let that = this
    let data = await C.ajax('/organization/diagnosis/getdiagnosis')
    if (data) {
      that.cates = data
    }
  },
  methods: {
    async callSubmit (index) {
      if (this.cid === '') {
        C.error('诊断所属主分类不能为空！')
        return false
      } else if (/^\s*$/.test(this.name)) {
        C.error('诊断名称不能为空！')
        return false
      }
      let data = {
        id: this.id,
        name: this.name,
        pid: this.cid
      }
      this.loading = true
      let res = await C.ajax('/organization/diagnosis/adddiagnose', { data: JSON.stringify(data) }, 'post')
      if (res) {
        this.loading = false
        this.$notify({
          title: '成功',
          message: res.data,
          type: 'success'
        })
        C.closeBrowserWindow(this.cid)
      }
    },
    close () {
      C.closewin()
    }
  }
}
</script>
<style>
.el-select-dropdown {
    top: 48px !important;
}
</style>